package com.neu.common.utils;

import org.springframework.validation.BindingResult;

/**
 * Yao
 * 验证实体类工具类
 */
public class ValidUtil {
    public static Result createResultByBindingResult(BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            StringBuilder error = new StringBuilder();
            bindingResult.getFieldErrors().forEach((item)->{
                error.append(item.getField() + "：" + item.getDefaultMessage() + System.lineSeparator());
            });
            return Result.error().setMessage(error.toString());
        }
        return null;
    }
}
